﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using CMSMVC4.Areas.Main.Models;
using CMSMVC4.Filters;

namespace CMSMVC4.Areas.Main.Controllers
{
    public class TimKiemController : Controller
    {
        //
        // GET: /Main/TimKiem/

        [ChildActionOnly]
        public ActionResult FormSearch(string id)
        {
            TimKiemModel model = new TimKiemModel();
            model.id = id;
            return PartialView(model);
        }

        [OutputCache(Duration = 900, VaryByParam = "id,page", Location = OutputCacheLocation.Client, NoStore = true)]
        public ActionResult TuKhoa(TimKiemModel model, string page)
        {
            if (ModelState.IsValid)
            {
                CommandSql cm = new CommandSql();
                ViewBag.Title = MultiResource.Resource.Title_Search;
                int count = cm.SetCountTimKiem(10, model.id);
                ViewBag.timkiem = cm.GetDataTimKiem(ref page, model.id);
                ViewBag.count = count;
                ViewBag.page = page;//phải dưới ham getdata
                //select menu dang chon
                ViewBag.Menu = 0;
                ViewBag.Model = model;
                return View();
            }
            return RedirectToAction("Index", "Home");
        }

        [ChildActionOnly]
        public string GetImg(int type)
        {
            CMSMVC4Entities db = new CMSMVC4Entities();
            var data = db.Menus.FirstOrDefault(x => x.Area == MenuArea.Home && x.Type == type);
            if (data != null) return data.Image;
            return "";
        }
    }
}
